//格式化时间
//dateTime：时间戳
function getFormtTime(dateTime,flag) {
    if(dateTime != null ) {
        //若传入的dateTime为字符串类型，需要进行转换成数值，若不是无需下面注释代码
        var time = parseInt(dateTime)
        var date = new Date(time);
        //获取年份
        var YY = date.getFullYear();
        //获取月份
        var MM = (date.getMonth() + 1 < 10 ? '0'+(date.getMonth() + 1) : date.getMonth() + 1);
        //获取日期
        var DD = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate());
        if(flag) { //flag为true，显示时分秒格式
            //获取小时
            var hh = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours());
            //获取分
            var mm = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes());
            ///获取秒
            var ss = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
            //返回时间格式： 2020-11-09 13:14:52
            return YY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss;
        } else {
            //返回时间格式： 2020-11-09
            return YY + '-' + MM + '-' + DD;
        }
    } else {
        return "";
    }
}
$.ajax({
    type: "post",
    url: "/orde/queryOrdeByCondition",
    data: {status:1},
    dataType: "json",
    success: function (r) {
        if (r!="null"){
            var t="<tr>\n" +
                "          <th>序号</th>\n" +
                "          <th>订单编号</th>\n" +
                "          <th>客户姓名</th>\n" +
                "          <th>联系电话</th>\n" +
                "          <th>订购时间</th>\n" +
                "          <th>金额</th>\n" +
                "          <th>操作人</th>\n" +
                "          <th>审核状态</th>\n" +
                "          <th>操作</th>\n" +
                "        </tr>"
            for (var i=0;i<r.length;i++){

                    t += "<tr> <td>" + r[i].rownum + "</td><td>" + r[i].orderid + "</td><td>" + r[i].custom.customname + "</td><td>" +r[i].custom.telephone+ "</td><td>"+getFormtTime(r[i].ordertime,false)+"</td><td>"+r[i].ordermoney+"</td><td>"+r[i].users1.uname+"</td><td>审核中</td><td>\n" +
                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">审核</a>\n" +
                        "          </td></tr>"
            }
            $(".tablelist").html(t)
            // var pagenum = document.getElementById("pagenum");
            $("#pagenum").html(r.pageNum)
            // var totalrows = document.getElementById("totalrows");
            // totalrows.innerHTML=r.totalRows
            $("#totalrows").html(r.totalRows)

            $(".tablelink").click(function() {

                var text = $(this).text();
                var orderid = $(this).parents("tr")[0].children[1].innerHTML
                if (text == "审核") {
                    window.location.href = "/orde/huoquId/" + orderid
                }
            })
        }else {
            alert("没有这类人哦！")
        }
    }
})

$("#check").click(function () {
    var orderNum = $("#orderNum").val();
    var customName = $("#customName").val();
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var startMoney = $("#startMoney").val();
    var endMoney = $("#endMoney").val();
    $.ajax({
        type: "post",
        url: "/orde/queryOrdeByCondition",
        data: {orderid: orderNum,customname:customName,ordertimeStart:startTime,ordertimeEnd:endTime,ordermoneyStart:startMoney,ordermoneyEnd:endMoney,status:1},
        dataType: "json",
        success: function (r) {
            if (r!="null"){
                var t="<tr>\n" +
                    "          <th>序号</th>\n" +
                    "          <th>订单编号</th>\n" +
                    "          <th>客户姓名</th>\n" +
                    "          <th>联系电话</th>\n" +
                    "          <th>订购时间</th>\n" +
                    "          <th>金额</th>\n" +
                    "          <th>操作人</th>\n" +
                    "          <th>审核状态</th>\n" +
                    "          <th>操作</th>\n" +
                    "        </tr>"
                for (var i=0;i<r.length;i++){

                    t += "<tr> <td>" + r[i].rownum + "</td><td>" + r[i].orderid + "</td><td>" + r[i].custom.customname + "</td><td>" +r[i].custom.telephone+ "</td><td>"+getFormtTime(r[i].ordertime,false)+"</td><td>"+r[i].ordermoney+"</td><td>"+r[i].users1.uname+"</td><td>审核中</td><td>\n" +
                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">审核</a>\n" +
                        "          </td></tr>"
                }
                $(".tablelist").html(t)
                // var pagenum = document.getElementById("pagenum");
                $("#pagenum").html(r.pageNum)
                // var totalrows = document.getElementById("totalrows");
                // totalrows.innerHTML=r.totalRows
                $("#totalrows").html(r.totalRows)

                $(".tablelink").click(function() {

                    var text = $(this).text();
                    var orderid = $(this).parents("tr")[0].children[1].innerHTML
                    if (text == "审核") {
                        window.location.href = "/orde/huoquId/" + orderid
                    }
                })
            }else {
                alert("没有这类人哦！")
            }
        }
    })
})
